<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="../../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=emulateIE7" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8">
<link rel="stylesheet" href="${ctx}/css/sapar.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/css/common.css" />
<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/sapar.js"></script>
<script type="text/javascript" src="${ctx}/js/WdatePicker.js"></script>
<script type="text/javascript" src="${ctx}/assets/layer/layer.js"></script>
<title>编辑公告</title>
</head>

<body>
    <div id="saper-container">
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">
                <h2>编辑公告</h2>
            </div>
			<div class="subfiled-content">
	            <form class="saper-form" id="dataForm">
	                <div class="kv-item clearfix">
	                    <label><span class="impInfo">*</span>排班标题：</label>
	                    <div class="kv-item-content">
	                        <input type="text" placeholder="排班标题" class="txt_required" name="shiftTitle" value="${shift.shiftTitle}" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
	                    </div>
	                </div>
	                <div class="kv-item clearfix">
	                    <label><span class="impInfo">*</span>上传人：</label>
	                    <div class="kv-item-content">
	                    	 <div class="user-name" style="line-height:30px;"  id="user-name">${emp.employeeLoginname}</div>
	                    	  <input type="text" placeholder="上传人id" class="txt_required" name="employeeName" value="${emp.employeeName}" style="display: none">
	                        <input type="text" placeholder="上传人id" class="txt_required" name="employeeId" value="${emp.employeeId}" style="display: none">
	                    </div>
	                </div>
					<div class="kv-item clearfix">
	                    <label>相关图片 ：</label>
	                    <div class="kv-item-content">
	                    	<input type="hidden" name="shiftImg" id="shiftImg" value="${shift.shiftImg}"/>
	                    	<input type="file" name="upPicFile" id="upPicFile" value="">
	                        <input type="button" id="uploadPic" value="上传" />
	                    </div>
	                </div>
	                <div class="buttons">
	                    <a href="javascript:;" class="sapar-btn sapar-btn-recom">确定</a>
	                    <input name="shiftId" type="hidden" value="${shift.shiftId}">
	                </div>
	                <div class="buttons">
	                    <input name="shiftSort" id="shiftSort" type="hidden" value="${shift.shiftSort}">
	                </div>
	            </form>
            </div>
        </div>
        <div id="saper-ft"></div>
    </div>
    

<script src="${ctx}/js/ajaxfileupload.js"></script>
<script type="text/javascript">
var leixing = <%= request.getAttribute("leixing") %>;
$(function(){
	$(".sapar-btn-recom").click(function(){
		 var btn = true;
		 $(".txt_required").each(function(){
			 var str =$(this).val();
			 if(isNullOrEmpty(str)){
				 btn = false;
				 layer.msg("必填项不为空");
				 return false;
			 }
		 });
		 if(btn){
			 $.ajax({
	             type: "POST",
	             url:"${ctx}/shift/shiftSave.do",
	             data:$('#dataForm').serialize(),// 你的formid
	             error: function(request) {
	            	 	layer.alert("网络故障，请稍后再试!");
	             },
	             success: function(data) {
	 	           	if(data.status=="true"){
		 	           	layer.alert("保存成功", function(){
		 	           		window.location.href="${ctx}/shift/wenkuList.do";
	           		    });
	 	           	}else{
	 	           		 layer.msg(data.msg);
	 	           	}
	             }
	         }); 
		 }
	});
	
	$("#uploadPic").click(function () {
  		 if($("#upPicFile").val()==''){
  			 layer.msg("请选择文件");
			 return false;
  		 }
        ajaxFileUpload();
    });
   
});

function ajaxFileUpload() {
    $.ajaxFileUpload({ 
        url: '${ctx}/upload/filesUploadPics.do?lx='+leixing, //用于文件上传的服务器端请求地址
        secureuri: false, //是否需要安全协议，一般设置为false
        fileElementId: 'upPicFile', //文件上传域的ID
        dataType: 'json', //返回值类型 一般设置为json
        success: function (data, status)  //服务器成功响应处理函数
        {
        	var msg = data.message;
        	var sort = data.sort;
        	if(data.error==1){
        		$("#shiftImg").val(msg);
        		$("#shiftSort").val(sort);
        		layer.alert('上传成功', {
             	    skin: 'layui-layer-lan'
             	    ,closeBtn: 0
             	    ,shift: 4 //动画类型
                 });
        	}else{
        		layer.alert('上传失败,'+msg, {
             	    skin: 'layui-layer-lan'
             	    ,closeBtn: 0
             	    ,shift: 4 //动画类型
                 });
        	}
        	
        },
        error: function (data, status, e)//服务器响应失败处理函数
        {
            alert("上传失败");
        }
    });
    return false;
}

function isNullOrEmpty(strVal){
	strVal = strVal.replace(/(^\s*)|(\s*$)/g,"");
	if(strVal == '' || strVal == null || strVal == undefined){
		return true;
	}else{
		return false;
	}
}
function getParameter(name) { 
   	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); 
   	var r = window.location.search.substr(1).match(reg); 
   	if (r!=null) return unescape(r[2]); return null;
}
</script>
</body>
</html>